<?php
/**
 * 日志管理类
 * 
 * @author  sunguide 
 * @version 1.0
 * @package main
 * @time 2013-9-24 11:58:31
 */
class LogAction extends Action {
	private $_uid = '';
	public function _initialize(){
		$this->_uid = session('uid');
		if(!$this->_uid) $this->display("Public:login");//(503,"对不起，您登录超时了，请重新登录！",1);
		//B('Authenticate', $action);
	}
    public function index(){
	
		
    }
	//所有用户登陆日志
	public function loginLog(){
		$Agent = $_SERVER['HTTP_USER_AGENT'];
		$LoginLog = M('LoginLog');
		$LogsLog = M('LogsLog');
		$ip = get_client_ip();
		import('ORG.Net.IpLocation');// 导入IpLocation类
		$Ip = new IpLocation('UTFWry.dat'); // 实例化类 参数表示IP地址库文件
		$area = $Ip->getlocation($ip); // 获取某个IP地址所在的位置
		
		//显示访问用户的浏览器信息
		//echo 'Browser: ' . determinebrowser($Agent) . '<BR>';
		//显示访问用户的操作系统平台
		//echo 'Platform: ' . determineplatform($Agent). '<BR>';
		$uid = $this->_uid;
		$data = array(
			'uid'	=> $uid,
			'ip'	=>$ip,
			'region'=>$area['area'],
			'country'=>$area['country'],
			'browser'=>determinebrowser($Agent),
			'os'	 =>determineplatform($Agent),
			'login_time'=>datetime(),
			'status' => session('login_status')?session('login_status'):0,    //1,正常登陆,0 失败
		);

		$v = $LoginLog->add($data);
		if($v){
			$result = array(
				'log_uid'  => $uid,
				'log_name' => $uid.'用户登陆记录成功',	
				'log_description' => '',
				'create_time' => datetime(),
				'status'	=> 1
			);
			$LogsLog->add($result);
		}else{
			$result = array(
				'log_uid'  => $uid,
				'log_name' => $uid.'用户登陆记录失败',	
				'log_description' => '',
				'create_time' => datetime(),
				'status'	=> 0
			);
			$LogsLog->add($result);
		}
	}
	public function LogoutLog(){

	}

}